package day6;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class Zhishu {
    public static void main(String[] args) {
        //规定：1不是质数
        Scanner scan = new Scanner(System.in);
        int a = 0;
        int count = 0;//计算除的次数
        while (a < 1) {//保证a>1
            System.out.print("输入一个正整数:");
            a = scan.nextInt();
        }
        if (a == 1) {
            System.out.println(a + "不是质数");
        } else {
            //范围是 2---到这个数的开平方+1
            boolean zhi = true;//假定他是质数
            for (int i = 2; i * i <= a && zhi; i++) {
                count++;
                if (a % i == 0) {
                    zhi = false;//不是
                }
            }
            System.out.println("计算了"+count+"次，得出了结论！");
            if (zhi) {
                System.out.println(a + "是质数");
            } else {
                System.out.println(a + "不是质数");
            }

        }
    }
}
